import { Http } from '@/network/request'
import { InfoDTO, Login, PwdDTO, UserInfo, UserState } from './data.d'

// 登录
export const login = (data: Omit<Login, 'nickname'>, isStr: boolean = true) => {
  return Http.post<typeof data, UserInfo & Pick<UserState, 'token'>>('/codeDuckUser/login', data, {
    typeStr: isStr ? '登录' : undefined,
  })
}
// 登录信息
export const info = () => {
  return Http.post<null, UserInfo>('/codeDuckUser/getByToken', null)
}
// 注册
export const register = (data: Login) => {
  return Http.post<typeof data, null>('/codeDuckUser/register', data, { typeStr: '注册' })
}
// 登出
export const logout = () => {
  return Http.post<null, null>('/codeDuckUser/logout', null, { typeStr: '登出' })
}
// 更新用户信息
export const updateInfo = (data: InfoDTO) => {
  return Http.post<typeof data, null>('/codeDuckUser/logout', data, { typeStr: '修改' })
}
// 修改密码
export const updatePassword = (data: PwdDTO) => {
  return Http.post<typeof data, null>('/codeDuckUser/logout', data, { typeStr: '修改密码' })
}
